<template>
    <div class="wrapper" ref="wrapper">
        <div>
            <slot></slot>
        </div>
    </div>
</template>

<script>
import BScroll from 'better-scroll'

export default {
    props: {
        probeType2: {
            type: Number,
            default: 0
        },
        pullUpLoad: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            scroll : null
        }
    },
    mounted() {
    //    const wrapper =  document.querySelector('.wrapper')
    //    console.log(wrapper)
    // console.log(this.$refs.wrapper)
    // 1. 创建better-scroll对象
       this.scroll = new BScroll(this.$refs.wrapper, {
            probeType: this.probeType2,
            click: true,
            pullUpLoad: this.pullUpLoad
       })

    // 2. 监听滚动距离x, y
        this.scroll.on('scroll', (position) => {
                this.$emit('scroll', position)
        })

    //  3. 上拉加载更多
        this.scroll.on('pullingUp', () => {
            this.$emit('pullingUp')
        })
    },
    methods: {
        scrollTo2(x, y, time = 500) {
            this.scroll.scrollTo(x, y, time)
        },
        finishPullUp1() {
            this.scroll.finishPullUp()
        },
        refresh2() { 
            console.log('1');
            this.scroll.refresh()   
        }
    }
}
</script>


<style scoped>
    
</style>